# coding=utf-8
from  urllib import request
import re
import os



'''    Urllib 模块提供了读取web页面数据的接口，我们可以像读取本地文件一样读取www和ftp上的数据 
    urlopen 方法用来打开一个url 
    read方法 用于读取Url上的数据 
'''
from urllib import parse,request
#输出内容:user=admin&password=admin
header_dict = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko'}
url='http://www.xfyy72.com/luanlun'
req = request.Request(url=url,headers=header_dict)
res = request.urlopen(req)
res = res.read()
res=res.decode("gb2312",'ignore')
#print(res)
#print(res.decode('gbk'))
imglist=re.findall(r'/pic.*?.jpg',res);

for i in imglist:
    #print(i)
    f=open("网易云下载音乐/"+str(i)[-10:],"wb")
    img=request.Request(url=('http://www.xfyy72.com/'+i),headers=header_dict);
    imgl=request.urlopen(img)
    f.write(imgl.read())
    f.flush()
    f.close()
urllist =re.findall(r'href=.*?[0-9]+?.html',res)
print(urllist)
for i in urllist:
    s='http://www.xfyy72.com/'+str(i)[6:]
   # print(s)
    if re.match(r'[0-9]',s[-11]):
        ress=request.Request(url=s,headers=header_dict)
        pagee=request.urlopen(ress).read()
       # print(s)
        pagee=pagee.decode('GB2312', 'ignore')
        #print(pagee)
       # break
        listt=re.findall(r"href='(.*0-0)'",pagee)
        for j in listt:
           print('http://www.xfyy72.com/'+j)





